package xyz.jcat.webflux.sucurity;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler;
import reactor.core.publisher.Mono;
import xyz.jcat.common.web.Resp;
import xyz.jcat.common.web.RespCodeMsg;

public class DefaultServerAuthenticationFailureHandler implements ServerAuthenticationFailureHandler {

    @Override
    public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception) {

        return ServerUtils.writeJson(webFilterExchange.getExchange(), Resp.fail(RespCodeMsg.ACCOUNT_OR_PWD_ERROR));
    }
}
